package org.viettan.android.main.activities.radio;

import org.viettan.android.main.R;
import org.viettan.android.main.activities.common.VietTanBaseListActivity;
import org.viettan.android.main.intents.IntentKeys;
import org.viettan.android.main.managers.RadioManager;
import org.viettan.android.main.model.RadioEpisode;
import org.viettan.android.main.model.RadioProgram;
import org.viettan.android.main.view.RadioEpisodeAdapter;
import org.viettan.android.main.view.RadioEpisodeAdapterFactory;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.google.inject.Inject;

/**
 * The {@code RadioProgramActivity} just displays the list of individual {@link RadioEpisode} for a
 * given {@code RadioProgram} (which really is just a day).
 */
public class RadioProgramActivity extends VietTanBaseListActivity {
    @Inject
    private RadioEpisodeAdapterFactory radioEpisodeAdapterFactory;
    @Inject
    private RadioManager radioManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	RadioProgram radioProgram = (RadioProgram) getIntent().getExtras().get(
		IntentKeys.RADIO_EPISODES.name());

	RadioEpisodeAdapter adapter = radioEpisodeAdapterFactory.create(this, R.layout.radio_row,
		radioProgram.getEpisodes());
	setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView listView, View view, int position, long id) {
	RadioEpisode radioEpisode = (RadioEpisode) getListAdapter().getItem(position);
	radioManager.play(radioEpisode);

	Intent radioEpisodeIntent = new Intent(this, RadioEpisodeActivity.class);
	startActivity(radioEpisodeIntent);
    }
}
